# -*- coding:utf-8 -*-
# @FileName  :t16.py
# @Time      :2021/7/15 16:03
import io
import re
import sys
import time

import execjs
import requests

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')


def jie():
    with open('t9_1.js', 'r', encoding='gbk') as f:
        jstext = f.read()
    ctx = execjs.compile(jstext)
    result = ctx.call('pp')
    return result


def main(f2):
    global num
    r = requests.get(f'http://match.yuanrenxue.com/match/9', headers=kv1)
    ss = r.cookies['sessionid']
    ob = re.findall('(<script type="application/javascript">)(.*)', r.text)[0][1].replace('</script>', '')
    r1 = requests.post(f'http://tool.yuanrenxue.com/api/ob2', headers=kv1, data={'m': ob}).json()
    with open('t9.js', encoding='utf-8') as sf:
        tt = sf.read()
    with open('t9_1.js', 'w', encoding='utf-8') as f:
        f.write(tt + '\n')
        try:
            f.write(
                r1['result'].replace('global', 'cao').replace('$c();\n}, 4000);', 'clearInterval(this);\n}, 4);').replace('h();', '').replace('l();','').replace
                ('decrypt', '_0x4f6d79').replace('window', 'caonim') + '\n')
        except:
            return main(f)
    m = jie()

    kv = {'User-Agent': 'yuanrenxue.project', 'cookie': f'sessionid={ss};{m.replace("; path=/", "")}'}
    r11 = requests.get(f'http://match.yuanrenxue.com/api/match/9?page={f2}', headers=kv).json()
    print(len(r11['data']))
    print(r11['data'])
    for i in r11['data']:
        num += i['value']


if __name__ == "__main__":
    num = 0
    # print()
    kv1 = {'User-Agent': 'yuanrenxue.project'}
    for i in range(1, 6):
        main(i)
        # input('1111')
    print(num)
